#include "argsFileParser.h"

#include <iostream>
#include <time.h>

using namespace std;


void printArgs(ArgsFileEntry *argsFileEntry, int depth = 0)
{
    for(int i = 0; i < depth; ++i)
        cout << "  ";

    cout << argsFileEntry->type << " : " << argsFileEntry->name;


    std::map<std::string, std::string>::iterator it;
    for(it = argsFileEntry->extraAttrs.begin();
        it != argsFileEntry->extraAttrs.end();
        it++)
    {
        cout << " | *" << it->first << " : " << it->second;
    }

    cout << endl;

    if( argsFileEntry->isGroup())
    {
        ArgsFileGroupEntry *group = (ArgsFileGroupEntry *)argsFileEntry;

        for(int i = 0; i < (int)group->children.size(); i++)
        {
            printArgs(group->children[i], depth + 1);
        }
    }
}


int main(int argc, char *argv[])
{
    string filepath  = "/home/joao/args/a.args";

    if(argc > 1)
    {
        filepath = string(argv[1]);
    }

    ArgsFile *argsFile = ArgsFile::parse(filepath);

    if(argsFile != NULL)
    {
        std::cout << " FORMAT: " << argsFile->format << std::endl;
        printArgs(argsFile);
        delete argsFile;
    }

    return 0;
}
